package com.example.administrator.zxygradute;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private LinearLayout ll_bar, ll_menu;
    private ScrollView sv_1;
    private ScrollView sv_2;
    private ScrollView sv_3;
    private ScrollView sv_4;
    private ScrollView sv_5;
    private View svArray[];
    private int[] resIds = new int[]{R.mipmap.banner1, R.mipmap.banner2, R.mipmap.banner1, R.mipmap.banner2, R.mipmap.banner1};
    private BarMoveView bmv;
    private View curView;
    private PDAMainPageSwipeLayout PDAMSL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImmersiveStatusBarUtil.initStateBarColor(this, 0xff07ABE8);

        ll_bar = (LinearLayout) findViewById(R.id.ll_bar);
        ll_menu = (LinearLayout) findViewById(R.id.ll_menu);
        sv_1 = (ScrollView) findViewById(R.id.sv_1);
        sv_2 = (ScrollView) findViewById(R.id.sv_2);
        sv_3 = (ScrollView) findViewById(R.id.sv_3);
        sv_4 = (ScrollView) findViewById(R.id.sv_4);
        sv_5 = (ScrollView) findViewById(R.id.sv_5);
        bmv = (BarMoveView) findViewById(R.id.bmv);
        PDAMSL = (PDAMainPageSwipeLayout) findViewById(R.id.PDAMSL);
        bmv.setColor(0xff07ABE8);
        bmv.setVisibility(View.INVISIBLE);

        svArray = new View[]{sv_1, sv_2, sv_3, sv_4, sv_5};

        for (int i = 0; i < ll_bar.getChildCount(); i++) {
            final TextView child = (TextView) ll_bar.getChildAt(i);
            if(i == 0){
                curView = child;
                bmv.setPosition(child);
            }
            child.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int j = 0; j < ll_bar.getChildCount(); j++) {
                        TextView tv_each = (TextView) ll_bar.getChildAt(j);
                        if(child == tv_each){
                            tv_each.setTextColor(0xff07ABE8);
                            svArray[j].setVisibility(View.VISIBLE);
                            bmv.setPosition(curView, tv_each);
                            curView = tv_each;
//                            ImageView iv_banner = (ImageView) svArray[j].findViewById(R.id.iv_banner);
//                            iv_banner.setImageResource(resIds[j]);
                        }else{
                            tv_each.setTextColor(0xffa0a0a0);
                            svArray[j].setVisibility(View.GONE);
                        }
                    }
                }
            });
        }

        for (int i = 0; i < ll_menu.getChildCount(); i++) {
            final TextView child = (TextView) ll_menu.getChildAt(i);
            child.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    for (int j = 0; j < ll_menu.getChildCount(); j++) {
                        TextView tv = (TextView) ll_menu.getChildAt(j);
                        if(child == tv){
                            tv.setBackgroundColor(0xff273444);
                            Toast.makeText(MainActivity.this, "" + tv.getText(), Toast.LENGTH_SHORT).show();
                        }else{
                            tv.setBackgroundColor(0xff2e3d50);
                        }
                    }
                }
            });

        }

    }
}
